import request from "@/utils/request";
import { defineStore } from "pinia";
import { ApiRes, BannerItem, Brand, GoodsItem, HotGoods } from "@/types/data";


const useHomeStore = defineStore('home', {
    state() {
        return {
            bannerList: [] as BannerItem[],
            newGoodsList: [] as GoodsItem[],
            hotGoodsList: [] as HotGoods[],
            // 品牌数据
            brandList: [] as Brand[],
        }
    },
    actions: {
        async getBannerList() {
            const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
            this.bannerList = res.data.result
        },
        async getNewGoodsList() {
            const res = await request.get<ApiRes<GoodsItem[]>>('/home/new')
            this.newGoodsList = res.data.result
        },
        async getHotGoodsList() {
            const res = await request.get<ApiRes<HotGoods[]>>('/home/hot')
            this.hotGoodsList = res.data.result
        },
        async getBrandList() {
            const res = await request.get<ApiRes<Brand[]>>('/home/brand')
            this.brandList = res.data.result
        }

    },
    getters: {}
})
export default useHomeStore